using System;
using System.Collections.Generic;
using Holoville.HOTween;
using Holoville.HOTween.Core;
using UnityEngine;

[Serializable]
public class SitPoint
{
	public delegate void OnComplete(bool showAfterSit, bool left);

	public Dictionary<string, string> animationsNames;

	public bool showAfterSit;

	public float leapDuration;

	public Transform inTransform;

	public pointExitFromCar[] pointExitFromCar;

	public float cLeapTime;

	private bool _enabled;

	private Humanoid _inObject;

	public bool free
	{
		get
		{
			return inObject == null;
		}
	}

	public Humanoid inObject
	{
		get
		{
			return _inObject;
		}
	}

	public bool enabled
	{
		get
		{
			return _enabled;
		}
		set
		{
			pointExitFromCar[] array = pointExitFromCar;
			foreach (pointExitFromCar pointExitFromCar2 in array)
			{
				pointExitFromCar2.gameObject.SetActive(value);
			}
			_enabled = value;
		}
	}

	public Transform GetIn(Humanoid obj, OnComplete onComplete)
	{
		_inObject = obj;
		_inObject.transform.parent = inTransform;
		_inObject.transform.localEulerAngles = Vector3.zero;
		_inObject.transform.localPosition = Vector3.zero;
		HOTween.Kill(this);
		HOTween.To(this, leapDuration, new TweenParms().Prop("cLeapTime", (!inObject.isDead) ? leapDuration : 0f).OnUpdate((TweenDelegate.TweenCallback)delegate
		{
			if (_inObject != null)
			{
				_inObject.transform.localEulerAngles = Vector3.zero;
				_inObject.transform.localPosition = Vector3.zero;
			}
		}).OnComplete((TweenDelegate.TweenCallback)delegate
		{
			cLeapTime = 0f;
			if (_inObject != null)
			{
				onComplete(showAfterSit, _inObject.transform.position.x < inTransform.position.x);
			}
		}));
		return inTransform;
	}

	public Transform GetOut(OnComplete start, OnComplete onComplete, bool withAnim)
	{
		if (_inObject != null && withAnim)
		{
			for (int i = 0; i < pointExitFromCar.Length; i++)
			{
				pointExitFromCar exitPoint = pointExitFromCar[i];
				Vector3 point = exitPoint.point;
				if (!(point != Vector3.zero))
				{
					continue;
				}
				start(showAfterSit, exitPoint.transform.localPosition.x > 0f);
				HOTween.Kill(this);
				HOTween.To(this, leapDuration, new TweenParms().Prop("cLeapTime", (!inObject.isDead) ? leapDuration : 0f).OnComplete((TweenDelegate.TweenCallback)delegate
				{
					if (_inObject != null)
					{
						_inObject.transform.parent = null;
						_inObject.transform.position = exitPoint.transform.position;
						_inObject.transform.eulerAngles = new Vector3(0f, exitPoint.transform.eulerAngles.y, 0f);
					}
					if (_inObject != null && exitPoint != null)
					{
						_inObject = null;
						onComplete(showAfterSit, exitPoint.transform.localPosition.x > 0f);
					}
					cLeapTime = 0f;
				}));
				return exitPoint.transform;
			}
		}
		cLeapTime = 0f;
		_inObject.transform.parent = null;
		inObject.transform.rotation = Quaternion.identity;
		_inObject = null;
		start(showAfterSit, true);
		onComplete(showAfterSit, true);
		return null;
	}

	public void Enable()
	{
	}

	public void Disable()
	{
		HOTween.Kill(this);
		if (_inObject != null)
		{
			_inObject.transform.SetParent(null);
			_inObject = null;
		}
	}
}
